package top.techqi.core.util

object FmtUtil {
    fun toBinString(value: Byte, prefix: String = "0b"): String {
        return prefix + Integer.toBinaryString(value.toInt() and 0xff)
            .padStart(8, '0')
    }

    fun toBinString(value: Short, prefix: String = "0b"): String {
        return prefix + Integer.toBinaryString(value.toInt() and 0xffff)
            .padStart(16, '0')
    }

    fun toBinString(value: Int, prefix: String = "0b"): String {
        return prefix + Integer.toBinaryString(value)
            .padStart(32, '0')
    }

    fun toBinString(value: Long, prefix: String = "0b"): String {
        return prefix + java.lang.Long.toBinaryString(value)
            .padStart(64, '0')
    }

    fun toHexString(value: Byte, prefix: String = "0x"): String {
        return prefix + Integer.toHexString(value.toInt() and 0xff)
            .padStart(2, '0')
    }

    fun toHexString(value: Short, prefix: String = "0x"): String {
        return prefix + Integer.toHexString(value.toInt() and 0xffff)
            .padStart(4, '0')
    }

    fun toHexString(value: Int, prefix: String = "0x"): String {
        return prefix + Integer.toHexString(value)
            .padStart(8, '0')
    }

    fun toHexString(value: Long, prefix: String = "0x"): String {
        return prefix + java.lang.Long.toHexString(value)
            .padStart(16, '0')
    }
}
